package com.news.news.web;


import com.news.news.modle.*;
import com.news.news.modle.System;
import com.news.news.service.IndexService;
import com.news.news.service.NewsDetailService;
import com.news.news.util.CommonResult;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping(path = "/newsDetail/newsDetailCtl")
public class NewsDetailController {
    @Resource
    NewsDetailService newsDetailService;

//新闻信息
    @RequestMapping(value = "/findNewsByid")
    public CommonResult findNewsByid(Integer id) {
        News newsByid = newsDetailService.findNewsByid(id);
        CommonResult commonResult = new CommonResult(200, newsByid, "成功");
        return commonResult;
    }

    /**
     * 查询文章点赞收藏评论数量
     * @param id
     * @return
     */
    @RequestMapping(value = "/findlikeCollectionNum")
    public CommonResult findlikeCollectionNum(Integer id) {

       int[] arr=newsDetailService.findlikeCollectionNum(id);

        CommonResult commonResult = new CommonResult(200, arr, "成功");
        return commonResult;
    }
    /**
     * 修改点赞数量,dz为true点赞，否则取消点赞
     * @param id
     * @return
     */
    @RequestMapping(value = "/updatelikeNum")
    public CommonResult updatelikeNum(Integer id,boolean dz,String newsName,@RequestHeader("userToken") String token) {/**/

       newsDetailService.updatelikeNum(id,dz,newsName,token);

        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }

    /**
     * 修改收藏数量,sc为true收藏，否则取消收藏
     * @param id
     * @return
     */
    @RequestMapping(value = "/updateCollectionNum")
    public CommonResult updateCollectionNum(Integer id,boolean sc,String newsName,@RequestHeader("userToken") String token) {

        newsDetailService.updateCollectionNum(id,sc,newsName,token);

        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }



    /**
     * 查询是否点赞、sc
     * @param id
     * @return
     */
    @RequestMapping(value = "/isUserDzSc")
    public CommonResult updateCollectionNum(Integer id,@RequestHeader("userToken") String token) {

        int[] userDzSc = newsDetailService.isUserDzSc(id, token);

        CommonResult commonResult = new CommonResult(200, userDzSc, "成功");
        return commonResult;
    }

    /**
     * 存储评论信息
     * @return
     */
    @RequestMapping(value = "/commentSent")
    public CommonResult commentSent(Comment comment, @RequestHeader("userToken") String token) {

         newsDetailService.commentSent(comment, token);

        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }


    /**
     * 发现新闻评论信息
     * @return
     */
    @RequestMapping(value = "/findComments")
    public CommonResult findComments(int id) {

       List<Comment> comments= newsDetailService.findComments(id);

        CommonResult commonResult = new CommonResult(200, comments, "成功");
        return commonResult;
    }
}
